//
//  ThreeDetailVC.m
//  mentor
//
//  Created by 孙宏峰的MacPro on 2018/7/11.
//  Copyright © 2018年 孙宏峰的MacPro. All rights reserved.
//

#import "ThreeDetailVC.h"

@interface ThreeDetailVC ()<UIWebViewDelegate>
@property (strong, nonatomic) UIWebView *webView;
@end

@implementation ThreeDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = self.navTitle;
  self.navigationItem.leftBarButtonItem = [self getBarButtonItemWithImage:[UIImage imageNamed:@"jiao_back"] withAction:@selector(basePopView) offset:-33];
    
    if([self.urlStr rangeOfString:@"?"].location != NSNotFound) {
        self.urlStr = [NSString stringWithFormat:@"%@&token=%@",self.urlStr,[CurrentUser shared].token];
    }else
    {
        self.urlStr = [NSString stringWithFormat:@"%@?token=%@",self.urlStr,[CurrentUser shared].token];
    }
//    self.urlStr = [self.urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];//ios 9以后
    NSURL *url = [NSURL URLWithString:self.urlStr];
    
    //TODO::测试
    NSURLRequest * request = [NSURLRequest requestWithURL:url cachePolicy:(NSURLRequestUseProtocolCachePolicy) timeoutInterval:30];
    
    NSLog(@"request:%@",request);
    [self.webView loadRequest:request];
    [self.view addSubview:self.webView];

}
- (void)basePopView
{
    /*!@brief ****   当前页面为编辑预约页 */
    if([self.urlStr rangeOfString:@"mentorZhiDaoStudentSelect.html"].location != NSNotFound) {
        NSMutableDictionary *dataDic = [[self.urlStr getURLParameters:self.urlStr] mutableCopy];
        [[NSNotificationCenter defaultCenter]postNotificationName:NOTIFICATION_GETURLPARAMETERS object:dataDic];
    }
    [self.navigationController popViewControllerAnimated:YES];
}
//通过图片自定义BarButtonItem 偏移
- (UIBarButtonItem *)getBarButtonItemWithImage:(UIImage *)image withAction:(SEL)action offset:(CGFloat)offset
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 44, 44);
    
    [btn setImageEdgeInsets:(UIEdgeInsetsMake(0, offset, 0, 0))];
    [btn setImage:image forState:UIControlStateNormal];
    
    [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *bit = [[UIBarButtonItem alloc]initWithCustomView:btn];
    
    return bit;
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    
    return YES;
}
#pragma mark - customDelegate
#pragma mark - event Response
#pragma mark - private methods
- (void)userCenter
{
    //    LoginVC *logVc = [LoginVC new];
    //    [self.navigationController presentViewController:logVc animated:YES completion:nil];
}
#pragma mark - getters and setters
- (UIWebView *)webView
{
    if (!_webView ) {
        _webView = [[UIWebView alloc] initWithFrame:(CGRectMake(0, 0, KScreenWidth, KScreenHeight - 64))];
        _webView.delegate = self;
        _webView.scrollView.bounces = NO;
    }
    return _webView;
}


@end
